﻿@model Kavaa.Modules.PortailMedical.Presentation.Models.MyViewModel
@using System.Web.Optimization
@using BootstrapSupport
@using NavigationRoutes

@{
    ViewBag.Title ="Ajouter Ressource";
    Layout =null;
}
<!DOCTYPE html>
@if (Session["user"] != null)
{
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>@ViewBag.Title</title>
        @*<meta name="viewport" content="width=device-width, initial-scale=1.0">*@
        <link href="@Styles.Url("~/content/css")" rel="stylesheet"/>
        <link href="@Styles.Url("~/Content/css-responsive")" rel="stylesheet" type="text/css" />
        @*@RenderSection("head", required: false)*@
        @Html.Partial("_html5shiv")
        @* favicons and touch icons go here *@
        @Scripts.Render("~/js")
       
        <script>
            var res;
         
            $(document).ready(function () {
                $("#ressource").change(function () {
                    res = $(this).val();
                    if (res == 2) {
                        document.getElementById("acte").style.display = "block";
                        document.getElementById("acteClinique").style.display = "block";
                        $('#acteClinique').load('/Clinique/ListActeByClinique');

                    }
                    else
                    {
                        document.getElementById("acte").style.display = "none";
                        document.getElementById("acteClinique").style.display = "none";
                    }
                });
            });
            function append() {
           
                var html = '<tr><td></td><td> Nom: <br />  <input type=\"text\" name=\"proprietenom\"/></td><td> Valeur: </br>  <input type=\"text\" name=\"proprietevaleur\"/></td><td> &nbsp;&nbsp; <button class=\"btn\" onclick=\"append()\" > Ajouter </button> </td></tr>';
                     $("#prop").after(html);
            }
          
            function save()
            {
              
                alert("toto");
                document.getElementById("loading").style.display = "block";
                $("#loading").fadeIn();
                var opts = {
                    lines: 12, // The number of lines to draw
                    length: 7, // The length of each line
                    width: 4, // The line thickness
                    radius: 10, // The radius of the inner circle
                    color: '#000', // #rgb or #rrggbb
                    speed: 1, // Rounds per second
                    trail: 60, // Afterglow percentage
                    shadow: false, // Whether to render a shadow
                    hwaccel: false // Whether to use hardware acceleration 
                };
                var target = document.getElementById('loading');
                var spinner = new Spinner(opts).spin(target);
                var actesbis = new Array();
                var proprietesname = new Array();
                var proprietesvalue = new Array();
                var categorie = document.getElementById("categorie").value;
                var j = 0; var k = 0; var l = 0;
                var a = document.getElementsByName("selectedactes");
                var b = document.getElementsByName("proprietenom");
                var c = document.getElementsByName("proprietevaleur");
                for (i = 0; i < a.length ; i++) {
                    if (document.getElementsByName("selectedactes")[i].checked == true) {
                        actesbis[j] = document.getElementsByName("selectedactes")[i].value;
                        //alert(actes[j]);
                        j++;
                    }
                }
                for (f = 0; f < b.length ; f++) {
                    proprietesname[k] = document.getElementsByName("proprietenom")[f].value;
                    // alert(proprietesname[k]);
                    k++;
                }
                for (g = 0; g < c.length ; g++) {
                    proprietesvalue[l] = document.getElementsByName("proprietevaleur")[g].value;
                    // alert(proprietesvalue[l]);
                    l++;
                }
                //alert("toto");
                //alert(proprietesvalue[0]);

                $.ajax({
                    url: '/Clinique/SaveRessource',//ça marche
                    async: false,
                    type: 'POST',
                    data: { actes: actesbis, proprietesname: proprietesname, proprietesvalue: proprietesvalue, categorie: categorie, ressource: res },
                    //data: "actes=" + actesbis,
                    success: function (data) {
                        for (m = 0; m < actesbis.length; m++) {
                            alert(actesbis[m]);
                        }
                        $('#div').load('/Clinique/RessourceSaved', { idcategorie: data });
                    }
                });
                //alert(res);
                //alert(document.getElementById("categorie").value);
                //alert(document.getElementsByName("proprietenom")[0].value);
                //alert(document.getElementsByName("proprietenom")[1].value);
                //alert(document.getElementsByName("proprietenom")[2].value);
                //alert(document.getElementsByName("proprietevaleur")[0].value);
                //alert(document.getElementsByName("proprietevaleur")[1].value);
                //alert(document.getElementsByName("proprietevaleur")[2].value);
            }
</script>
<style> 
 #loading
    {
        display:none;
        /*position:fixed;*/
        left:inherit;
        top:inherit;
        width:inherit;
        height:inherit;
        background:rgba(255,255,255,0.8);
       /*z-index:1000;*/
    }
  
    #loadingcontent
    {
        display:table;
        position:absolute;
        left:inherit;
        top:inherit;
        width:inherit;
        height:inherit;
        font-size:12px;
    }
        
    #loadingspinner
    {
        display: table-cell;
        position:inherit;
        vertical-align:middle;
        width: inherit;
        text-align: center;
        font-size:larger;
        padding-top:inherit;
    }
    

.multi-list 
{
    float: left;
    padding-right: 50px;
}

.clear
{
    clear: both;
}
.fieldset {
    border: 1px solid #ccc;
    padding: 10px;
}
         
             .form-signin {
        
        padding: 19px 29px 29px;
        margin: 0 auto 20px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
        </style>
         <div class="navbar navbar-inverse navbar-top" >
           <div class="navbar-inner">
        </div>       
            </div>
               <div class="container">
     @{
         
         
    var prenomuser = ((Kavaa.Modules.PortailMedical.Entity.Utilisateur)(Session["user"])).Prenom;
    var nomuser = ((Kavaa.Modules.PortailMedical.Entity.Utilisateur)(Session["user"])).Name;}
          <table class="container">
              <tr>
                  <td>
            <img src="/Content/images/mediciMaroc.png" /> </td>
                  <td class="pull-right">
                      <br />
            <p style="text-align:right"><i class=" icon-user"> </i>&nbsp; &nbsp; @prenomuser  @nomuser  &nbsp; &nbsp;  @Html.ActionLink("Se déconnecter", "Deconnexion")&nbsp; &nbsp; </p>
               </td>
           
        
        </tr>
        </table>
                   </div>
    </head>
   
    <body style="padding:0px; background-color:#fafafa">
       
        <div class="container">
            @Html.Partial("_alerts")
            @Html.Partial("_validationSummary")
           
        
     <!-- Main hero unit for a primary marketing message or call to action -->

  

<div id="result">
    

<div class="container" style="background-color:white">
   <div class="navbar">
   <div class="navbar-inner">
      <div class="container">
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>
          <div class="nav-collapse collapse">
        <ul class="nav">
      <li> @Html.ActionLink("Accueil", "AccueilClinique")</li>
      <li > @Html.ActionLink("Accréditations", "Accreditations")</li>
      <li>@Html.ActionLink(" Réservations", "Reservations")</li>
      <li class="active">@Html.ActionLink("Gérer Ressources", "GererRessources")</li>
      <li>@Html.ActionLink("Admission des patients", "AdmissionPatient")</li>
      <li>@Html.ActionLink("Comptes Clinique", "ComptesClinique")</li>
  
    </ul>
  <form class="navbar-search pull-right">
      <i class="icon-search"></i>
  <input type="text" class="search-query" placeholder="Recherche">
</form>
              </div>
          </div>
  </div>
           
</div>

     <div style="padding-top:30px;padding-left:-10px;margin-right:5px; font-size:16px" >
          <table style="width:100%">
            <tr>
                <td  style="width:20%" >
            
           <div class="span3" style="margin-right:20px; margin-left:3px; width:230px">
          <div class="well">
            <ul class="nav nav-list">
              <li class="nav-header"></li>
               <li> @Html.ActionLink("Déclarer actes", "GererRessources")</li>
              
             <li class="active">@Html.ActionLink("Ajouter ressource", "AjoutRessource")</li>

               <li >@Html.ActionLink("Liste Ressources", "ListRessourcesClinique")</li>
             
            </ul>
          </div>
        </div>
                    </td>
                <td> Veuillez remplir les informations de la ressource que vous voulez ajouter:</td>
                </tr>
              <tr>
                  <td></td>
                <td style="width:80%">
                     <table  style="width:auto;margin-right:50px;margin-left:50px">
              <tr >
                 <td style="margin-right:50px;margin-left:50px">
        @{ var ressources = new SelectList(@ViewBag.ressources, "Id", "Name");}
                   &nbsp;&nbsp; &nbsp;Type Ressouce :
     
                 </td>
                  <td>
                          @Html.DropDownListFor(model => model.Ressource.Id, @ressources, "--Choix", new { id = "ressource" })
                  </td>
                  </tr>
                  <tr> 
                  <td>
                  &nbsp;&nbsp; &nbsp;Nom de la ressource :
                  </td>
                  <td> 
                        <input type="text" id="categorie" /><br />
                  </td>
                  </tr>
              <tr id="prop">
                  <td >  &nbsp;&nbsp; &nbsp; Propriétés:</td>
                  <td> Nom: <br />
                      <input type="text" name="proprietenom"/>
                  </td>
                  <td> Valeur: <br />
                       <input type="text" name="proprietevaleur"/></td>
                  <td> &nbsp;&nbsp; <button class="btn" onclick="append()" > Ajouter </button> </td>
              </tr>
               <tr >
                   <td id="acte" style="display:none">   &nbsp;&nbsp; &nbsp;  Actes supportés:</td>
                   <td >
                       <div id="acteClinique" style="display:none"></div>
                   </td>
              </tr>
              <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td>
                  <button class="btn btn-primary" onclick="save()" > Enregistrer </button>
                      </td>
              </tr>
             
        <tr>
            <td></td><td><div id="loading" style="font-family:'Times New Roman';font-size:20px;display:none">
                                        <div id="loadingcontent">
                                            <p id="loadingspinner">
                                                Enregistrement...   &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; .  
                                            </p>
                                        </div>
                              </div></td></tr>
                   </table>
    

                </td>
                </tr>

              </table>

   </div>
  


</div>
 
            <hr>
            <footer>
                <p>&copy; Kavaa @System.DateTime.Now.ToString("yyyy")</p>
            </footer> 
        </div>
        @* @Scripts.Render("~/js")*@
        @* @RenderSection("Scripts", required: false)*@
    </body>
</html>
     }
else{
 
  <h5>  Pour pouvoir accéder à cette page veuillez vous connecter :  @Html.ActionLink("Se connecter","SignIn","test") </h5>

}